package com.lagou.edu.filter;

import com.lagou.edu.service.DemoService;
import com.lagou.edu.utils.IpRecordUtil;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Activate(group = CommonConstants.CONSUMER)
public class TransportIpFilter implements Filter {

    Logger logger = LoggerFactory.getLogger(TransportIpFilter.class);

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
//        logger.info("获取请求IP:{}", IpRecordUtil.getIp());
        RpcContext.getContext().setAttachment(DemoService.REMOTE_IP_CONTEXT_KEY, IpRecordUtil.getIp());
        return invoker.invoke(invocation);
    }
}
